package org.neurone.domain.persistence;

import java.util.List;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.JoinColumn;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;
import javax.persistence.Table;

import org.neurone.domain.Application;
import org.neurone.domain.UserConfig;
import org.neurone.domain.UserDetailInfo;
import org.neurone.domain.alter.UserInfoAlter;

/**
 * 用户
 * @author Administrator
 *
 */
@Entity
@Table(name="TUserInfo")
public class UserInfoPersistence extends UserInfoAlter implements java.io.Serializable {
	
	/**
	 * 
	 */
	protected static final long serialVersionUID = 8609160678318290088L;

	
	/* (non-Javadoc)
	 * @see org.neurone.domain.IUserInfo#getUserID()
	 */
	@Id
	@GeneratedValue(strategy=GenerationType.AUTO)
	public Long getUserID() {
		return userID;
	}

	/* (non-Javadoc)
	 * @see org.neurone.domain.IUserInfo#getUserName()
	 */
	@Column
	public String getUserName() {
		return userName;
	}

	/* (non-Javadoc)
	 * @see org.neurone.domain.IUserInfo#getPasswd()
	 */
	@Column
	public String getPasswd() {
		return passwd;
	}

	/* (non-Javadoc)
	 * @see org.neurone.domain.IUserInfo#getUserNick()
	 */
	@Column
	public String getUserNick() {
		return userNick;
	}

	/* (non-Javadoc)
	 * @see org.neurone.domain.IUserInfo#getRealName()
	 */
	@Column
	public String getRealName() {
		return realName;
	}

	/* (non-Javadoc)
	 * @see org.neurone.domain.IUserInfo#getImage()
	 */
	@Column
	public String getImage() {
		return image;
	}

	/* (non-Javadoc)
	 * @see org.neurone.domain.IUserInfo#getEmail()
	 */
	@Column
	public String getEmail() {
		return email;
	}

	/* (non-Javadoc)
	 * @see org.neurone.domain.IUserInfo#getStatus()
	 */
	@Column
	public String getStatus() {
		return status;
	}

	/* (non-Javadoc)
	 * @see org.neurone.domain.IUserInfo#getUserConfig()
	 */
	@Override
	@OneToOne(cascade=CascadeType.ALL, targetEntity=UserConfigPersistence.class)
	public UserConfig getUserConfig() {
		return this.userConfig;
	}


	@Override
	@OneToMany(mappedBy="belongUser",targetEntity=UserDetailInfoPersistence.class)
	public List<UserDetailInfo> getUserDetailInfoList() {
		return this.userDetailInfoList;
	}
	
	@Override
    @ManyToMany(
            targetEntity=ApplicationPersistence.class,
            cascade ={CascadeType.PERSIST,CascadeType.MERGE},
            fetch=FetchType.LAZY
    )
    @JoinTable(
            name="TUser_Application",
            joinColumns={@JoinColumn(name="userID")},
            inverseJoinColumns={@JoinColumn(name="applicationID")}
    )
	public Set<Application> getAssignedApplicationList() {
		return assignedApplicationList;
	}
	
	public void setUserID(Long userID)
	{
		this.userID = userID;
	}
	public void setUserConfig(UserConfig userConfig) {
		this.userConfig = userConfig;
	}

	public void setUserDetailInfoList(List<UserDetailInfo> userDetailInfoList) {
		this.userDetailInfoList = userDetailInfoList;
	}	
	
	public void setAssignedApplicationList(Set<Application> assignedApplicationList) {
		this.assignedApplicationList = assignedApplicationList;
	}
}
